#pragma once
#include<pthread.h>


namespace kzz
{
    class Mutex
    {
        public:
        Mutex()
        {
            int n=pthread_mutex_init(&_mutex,nullptr);
            (void)n;
        }
        ~Mutex()
        {
            int n=pthread_mutex_destroy(&_mutex);
            (void)n;
        }
        void Lock()
        {
            int n=pthread_mutex_lock(&_mutex);
            (void)n;
        }
        void UnLock()
        {
            int n=pthread_mutex_unlock(&_mutex);
            (void)n;
        }

        private:
        pthread_mutex_t  _mutex;

    };


    class LockGuard
    {
        public:
        
        LockGuard(Mutex& mutex):_mutex(mutex)
        {
            _mutex.Lock();
        }
        ~LockGuard()
        {
            _mutex.UnLock();
        }


        private:
        Mutex _mutex;

    };
}